package com.example.demo.utils.calculate;

import com.example.demo.vo.PerformanceAnalysisEntity;
import com.example.demo.vo.PerformanceAnalysisInfo;
import com.example.demo.vo.PerformanceAnalysisVO;

/**
 * Created by 落羽 on 2017/8/1.
 */
public class PerformanceAnalysisCalculate {
    double g = 9.8; // m/s^2 重力加速度
    double gamma = 9800; // kg/m^3 水重度
    double Qgj_max = 211; // m^3/s 机组最大过机流量
    double Zwk = 572.8; // m 蜗壳进口压力表高程
    double Zws = 572.8; // m 尾水管出口压力表高程
    double nsl_sj = 94; // % 水轮机设计效率
    double nfd = 96; // % 发电机效率

    /**
     * @param Zsy
     * @param Zxy
     * @return
     */
    public  double calculHg( double Zsy,  double Zxy){
         double Hg = (Zsy - Zxy);
        return Hg;
    }

    /**
     * @param Pwk
     * @param Pws
     * @return
     */
    public  double calculH( double Pwk,  double Pws){
         double H = (Zwk + (Pwk * 1000 / gamma)) - (Zws + (Pws * 1000 / gamma)) ;
        return H;
    }

    /**
     * 数据初步处理
     * @param pav
     * @return
     */
    public PerformanceAnalysisEntity calculSecondary(PerformanceAnalysisVO pav){
        PerformanceAnalysisEntity pae = new PerformanceAnalysisEntity();
        switch (pav.getUnitInfo()){
            case 0:
            case 1:
            case 2:
                pae.setQfd(pav.getQgj());
                pae.setQqy(0);
                pae.setQdl(0);
                break;
            case 3:
            case 4:
            case 5:
                pae.setQdl(pav.getQgj());
                pae.setQqy(Math.min(Qgj_max, pav.getQqs()));
                pae.setQfd(0);
                break;
            case 6:
            case 7:
                pae.setQqy(0);
                pae.setQfd(0);
                pae.setQdl(0);
                break;
            default:
                pae.setQqy(0);
                pae.setQdl(0);
                pae.setQfd(0);
        }

        pae.setHg(calculHg(pav.getZsy(), pav.getZxy()));
        pae.setH(calculH(pav.getPwk(), pav.getPws()));
        pae.setDeltaH(pae.getHg() - pae.getH());
        pae.setNsl_sh(pav.getPdq() / (g * pae.getH() * pae.getQfd() * nfd / 100));
        pae.setPdq(pav.getPdq());
        return pae;
    }

    /**
     * 计算单点水能指标
     * @param pae
     * @return
     */
    public PerformanceAnalysisInfo calculUnitWater(PerformanceAnalysisEntity pae){
        PerformanceAnalysisInfo pai = new PerformanceAnalysisInfo();
        double Esj = 0;
        double Exs = 0;
        double Egs = 0;
        double Eys = 0;
        double Edl = 0;
        double Eqy = 0;
        double Esn = 0;
        double Lsn = 0;
//        if (listpae == null || listpae.size() == 0){
//            return null;
//        }
//        for (PerformanceAnalysisEntity pae : listpae){
//
//        }
        Esj = (pae.getPdq()) / 60;
        pai.setEsj(Esj);
        Exs = ((nsl_sj / 100) - pae.getNsl_sh()) * (nfd / 100) * g * pae.getDeltaH() * pae.getQfd() / 60;
        pai.setExs(Exs);
        Egs = (1 - ((nsl_sj / 100) * (nfd / 100))) * g * pae.getDeltaH() * pae.getQfd() / 60;
        pai.setEgs(Egs);
        Eys = (g * pae.getDeltaH() * pae.getQfd()) / 60;
//        System.out.println(Eys);
        pai.setEys(Eys);
        Edl = (g * pae.getHg() * pae.getQdl()) / 60;
        pai.setEdl(Edl);
        Eqy = (g * pae.getHg() * pae.getQqy()) / 60;
        pai.setEqy(Eqy);
        Esn = (Esj + Exs + Egs + Eys + Edl + Eqy);
        pai.setEsn(Esn);
        Lsn = (Esj / Esn);
        pai.setLsn(Lsn);
        return pai;
    }


    public static void main(String[] args) {
        PerformanceAnalysisVO pav = new PerformanceAnalysisVO();
        PerformanceAnalysisVO pav2 = new PerformanceAnalysisVO();
        PerformanceAnalysisVO pav3 = new PerformanceAnalysisVO();
        // 第一组测试数据
        pav.setUnitInfo(1);
        pav.setElj(0);
        pav.setPdq(260000.02);
        pav.setZsy(725.02);
        pav.setZxy(583.62);
        pav.setQqs(0);
        pav.setQgj(207.11);
        pav.setPwk(1453.31);
        pav.setPws(121.87);

        // 第11组测试数据
        pav2.setUnitInfo(5);
        pav2.setElj(43330);
        pav2.setPdq(0);
        pav2.setZsy(725.02);
        pav2.setZxy(583.62);
        pav2.setQqs(0);
        pav2.setQgj(3.01);
        pav2.setPwk(1456.11);
        pav2.setPws(122.01);

        // 第14组测试数据
        pav3.setUnitInfo(5);
        pav3.setElj(43330);
        pav3.setPdq(0);
        pav3.setZsy(725.02);
        pav3.setZxy(583.62);
        pav3.setQqs(0);
        pav3.setQgj(3.15);
        pav3.setPwk(1456.11);
        pav3.setPws(122.01);

        PerformanceAnalysisCalculate pac = new PerformanceAnalysisCalculate();
        PerformanceAnalysisEntity pae = pac.calculSecondary(pav);
        PerformanceAnalysisInfo pai = pac.calculUnitWater(pae);
//        System.out.println(pai.getEys());
        System.out.println(pae.toString());
        System.out.println(pai.toString());
    }
}
